window.addEventListener('load', function() {
    var mySwiper = new Swiper('.swiper', {
        loop: true, // 循环模式选项
        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
        },

        // 如果需要前进后退按钮
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
    })


    //海量api渲染数据
    let apilist = [{
            imgUrl: './images/api01.svg',
            title: '生活服务',
        },
        {
            imgUrl: './images/api02.svg',
            title: '金融科技',
        },
        {
            imgUrl: './images/api03.svg',
            title: '交通地理',
        },
        {
            imgUrl: './images/api04.svg',
            title: '充值缴费',
        },
        {
            imgUrl: './images/api05.svg',
            title: '数据智能',
        },
        {
            imgUrl: './images/api06.svg',
            title: '企业工商',
        },
        {
            imgUrl: './images/api07.svg',
            title: '应用开发',
        },
        {
            imgUrl: './images/api08.svg',
            title: '电子商务',
        },
        {
            imgUrl: './images/apic1.svg',
            title: '吃喝玩乐',
        },
        {
            imgUrl: './images/apic2.svg',
            title: '文娱视频',
        },

    ]
    let obj = {
        x: '11',
        fn: fn1
    };

    function fn1() {}
    // console.log(apilist);
    //定义变量保存数据
    let apiHtml = '';
    // 遍历
    apilist.forEach(function(v) {
            apiHtml += `
        <li>
            <img src="${v.imgUrl}" alt="">
            <h3>${v.title}</h3>
    </li> `
                // console.log(v);
        })
        // 添加到相应位置
    apiList.innerHTML = apiHtml;


    // 添加效果
    //获取元素
    let aDom = document.querySelectorAll('#main ul li')
        // console.log(aDom)
        // 遍历
    aDom.forEach(function(v) {
        // console.log(v);
        // 移入效果

        // 定义变量保存原图地址
        let oldSrc = '';

        v.addEventListener('mouseover', function() {
            // console.log(111)
            this.style.backgroundColor = '#2f7ee9';
            this.lastElementChild.style.color = '#fff';

            // 获取到图片的地址
            let imgSrc = this.firstElementChild.src
                // console.log(imgSrc)
            oldSrc = imgSrc;
            // 截取字符串
            let cutUrl = imgSrc.substring(0, imgSrc.lastIndexOf('.'))
            this.firstElementChild.src = `${cutUrl}-c.svg`;

        })

        // 移出效果
        v.addEventListener('mouseout', function() {
            this.style.backgroundColor = '';
            this.lastElementChild.style.color = '';
            this.firstElementChild.src = oldSrc;
        })
    })


    // 轮播图
    // 获取元素
    let items = document.querySelectorAll('#help .items')
    console.log(items);
    // 定义变量
    let index = 0;
    items[index].style.display = 'block';
    window.setInterval(function() {
        items[index].style.display = 'none';
        index++;
        if (index == items.length) {
            index = 0;
        }
        items[index].style.display = 'block';
    }, 2000)

    // 返回头部
    // 获取到元素
    let Rtop = document.getElementById('Rtop')
        // console.log(Rtop);
    window.addEventListener('scroll', function() {
        // 获取浏览器高度
        let sTop = document.documentElement.scrollTop
            // console.log(sTop)
            // 隐藏功能
        if (sTop >= 1000) {
            Rtop.style.display = 'block'
        } else {
            Rtop.style.display = 'none'

        }
        Rtop.addEventListener('click', function() {

            // 返回功能
            let timeId = window.setInterval(function() {
                let sTop = document.documentElement.scrollTop
                document.documentElement.scrollTop = sTop - 10;
                if (sTop <= 0) {
                    window.clearInterval(timeId)
                }
            }, 800)
        })
    })
})